package com.stef.saas.crm.api.v1;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.stef.saas.common.base.dto.BaseResult;
import com.stef.saas.crm.model.dto.CustomerDTO;
import com.stef.saas.crm.model.dto.CustomerPageDTO;
import com.stef.saas.crm.service.ICustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author stef
 * @date 2021-05-15
 */
@Api(value = "客户控制器V2",tags = "客户控制器V2")
@RestController
@RequestMapping("/crm/v2/customer")
@Validated
public class CustomerControllerV2 {


    @Autowired
    private ICustomerService customerService;


    @ApiOperation(value = "分页查询")
    @GetMapping("/list")
    public BaseResult pageListProduct(@Valid  Page page, CustomerPageDTO pageDto){
        return customerService.pageListCustomer(page, pageDto);
    }


    @ApiOperation(value = "添加")
    @PostMapping("")
    public BaseResult addProduct(@Valid @RequestBody CustomerDTO dto){
        return customerService.doSave(dto);
    }


    @ApiOperation(value = "删除")
    @DeleteMapping("/{id}")
    public BaseResult deleteProduct(@ApiParam(name = "id",value = "id",required = true) @PathVariable @NotNull(message = "id不能为空") Integer id){
        return customerService.doDelete(id);
    }


    @ApiOperation(value = "更新")
    @PutMapping("")
    public BaseResult updateProduct(@Valid @RequestBody CustomerDTO dto){
        return customerService.doUpdate(dto);
    }

    @ApiOperation(value = "查询详情")
    @GetMapping("/{id}")
    public BaseResult detail(@ApiParam(name = "id",value = "id",required = true) @PathVariable @NotNull(message = "id不能为空") Integer id){
        return customerService.detail(id);
    }
}
